﻿@{
    ViewData["Title"] = "添加分类";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>添加分类</title>
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form layui-form-pane" action="">
       <div class="layui-form-item">
    <label class="layui-form-label"><span style="color:red">*</span> 分类名称</label>
    <div class="layui-input-block">
        <input type="text" name="ItemTypeName" autocomplete="off" placeholder="请输入分类名称" lay-verify="required" class="layui-input">
    </div>
</div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>父分类</label>
            <div class="layui-input-inline">
                <select name="ParentTypeId" lay-filter="aihao" disabled>
                    <option value=""></option>
                    <option selected id="select"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span style="color:red">*</span>显示排序</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="number" name="OrderNum" placeholder="" autocomplete="off" class="layui-input" lay-verify="required" min="0" step="1" lay-affix="number">
                </div>
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">物料/产品</label>
            <div class="layui-input-block">
                <input type="radio" name="ItemOrProduct" value="item" title="物流" checked>
                <input type="radio" name="ItemOrProduct" value="product" title="产品">
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">启用状态</label>
            <div class="layui-input-block">
                <input type="radio" name="EnableFlag" value="Y" title="是" checked>
                <input type="radio" name="EnableFlag" value="F" title="否">
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit lay-filter="demo2">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary">取消</button>
        </div>
    </form>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        var selectedParentTypeId =  sessionStorage.getItem('ParentTypeId');//获取父分类ID
        if (selectedParentTypeId!= null) {  
            $('#select').val(selectedParentTypeId);//设置父分类下拉框默认值
        }
        document.getElementById('select').innerHTML = sessionStorage.getItem('ItemTypeName');//设置父分类下拉框显示值
        layui.use(['form'], function () {
            var form = layui.form;
            var layer = layui.layer;
            // 提交事件
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                $.get('/Song/AddMdItemTypeAsyncs', field, function (res) {
                    if (res > 0) {
                        layer.msg('保存成功', {
                            icon: 1,
                            time: 2000
                        } , function () {
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index);//再执行关闭
                        });
                    } else {
                        layer.msg("名称已存在",{
                            icon:2, 
                            time:2000
                        });
                    }
                });
                return false; // 阻止默认 form 跳转
            });   
        });
    </script>
</body>
</html>